package com.ruoyi.ly.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ruoyi.ly.domain.MobileIndustry;
import com.ruoyi.ly.domain.dto.MobileIndustryAddDTO;
import com.ruoyi.ly.domain.dto.MobileIndustryUpdateDTO;
import com.ruoyi.ly.domain.dto.PageMobileIndustryDTO;
import com.ruoyi.ly.domain.vo.MobileIndustryVO;
import com.ruoyi.ly.domain.vo.PageMobileIndustryVO;
import com.ruoyi.ly.mapper.MobileIndustryMapper;
import com.ruoyi.ly.service.MobileIndustryService;
import com.ruoyi.ly.utils.PageResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MobileIndustryServiceImpl implements MobileIndustryService {

    @Autowired
    private MobileIndustryMapper mobileIndustryMapper;

    @Override
    public void update(MobileIndustryUpdateDTO mobileIndustryUpdateDto) {
        MobileIndustry mobileIndustry =new MobileIndustry();
        BeanUtils.copyProperties(mobileIndustryUpdateDto,mobileIndustry);
        mobileIndustryMapper.update(mobileIndustry);
    }

    @Override
    public void save(MobileIndustryAddDTO mobileIndustryAddDTO) {
        MobileIndustry mobileIndustry =new MobileIndustry();
        BeanUtils.copyProperties(mobileIndustryAddDTO,mobileIndustry);
        mobileIndustry.setCreateTime(String.valueOf(System.currentTimeMillis()));
        mobileIndustryMapper.insert(mobileIndustry);
    }

    @Override
    public PageResult pageQuery(PageMobileIndustryDTO pageMobileIndustryDTO) {
        PageHelper.startPage(pageMobileIndustryDTO.getPage(), pageMobileIndustryDTO.getPageSize());
        Page<PageMobileIndustryVO> page = mobileIndustryMapper.pageQuery(pageMobileIndustryDTO);
        long total = page.getTotal();
        List<PageMobileIndustryVO> records = page.getResult();
        return new PageResult(total,records);
    }

    @Override
    public void delete(Long id) {
        mobileIndustryMapper.delete(id);
    }

    @Override
    public MobileIndustryVO selectById(Long id) {
        MobileIndustryVO mobileIndustryVO = mobileIndustryMapper.selectById(id);
        return mobileIndustryVO;
    }
}
